package com.qdu.average;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class AverageReducer extends Reducer<Text, LongWritable,Text,LongWritable> {
    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        Long sum=0L;
        Long count=0L;
        for (LongWritable val:values){
            sum+=val.get();
            count++;
            System.out.println(sum+"////////////");
        }
        context.write(key,new LongWritable(sum/count));
    }
}
